package com.mui.manager
{
	import flash.utils.*;
	
	public class ToolTipPool extends Object
	{
		private static var pools:Dictionary = new Dictionary();
		
		public function ToolTipPool()
		{
		}
		
		private static function getPool(classname:Class) : Array
		{
			if (!(classname in pools))
			{
				pools[classname] = [];
			}
			
			return pools[classname] as Array;
		}
		
		public static function getObject(classname:Class) : *
		{
			var pool:Array = getPool(classname);
			if (pool.length > 10)
			{
				return pool.pop();
			}
			return construct(classname, pool);
		}
		
		public static function disposeObject(value:*, classname:Class = null) : void
		{
			var name:String = null;
			if (!classname)
			{
				name = getQualifiedClassName(value);
				classname = getDefinitionByName(name) as Class;
			}
			var arr:* = getPool(classname);
			arr.push(value);
		}
		
		private static function construct(classname:Class, pool:Array) : *
		{
			switch(pool.length)
			{
				case 0:
				{
					return new classname;
				}
				case 1:
				{
					return new classname(pool[0]);
				}
				case 2:
				{
					return new classname(pool[0], pool[1]);
				}
				case 3:
				{
					return new classname(pool[0], pool[1], pool[2]);
				}
				case 4:
				{
					return new classname(pool[0], pool[1], pool[2], pool[3]);
				}
				case 5:
				{
					return new classname(pool[0], pool[1], pool[2], pool[3], pool[4]);
				}
				case 6:
				{
					return new classname(pool[0], pool[1], pool[2], pool[3], pool[4], pool[5]);
				}
				case 7:
				{
					return new classname(pool[0], pool[1], pool[2], pool[3], pool[4], pool[5], pool[6]);
				}
				case 8:
				{
					return new classname(pool[0], pool[1], pool[2], pool[3], pool[4], pool[5], pool[6], pool[7]);
				}
				case 9:
				{
					return new classname(pool[0], pool[1], pool[2], pool[3], pool[4], pool[5], pool[6], pool[7], pool[8]);
				}
				case 10:
				{
					return new classname(pool[0], pool[1], pool[2], pool[3], pool[4], pool[5], pool[6], pool[7], pool[8], pool[9]);
				}
				default:
				{
					return null;
					break;
				}
			}
		}
		
	}
}
